// 设置轮播图
import { BannerType } from '../types/banner'
import request from '../utils/request'

// 新增轮播图
export const BannerPost = (obj: BannerType) => {
    return request.post('classes/banner', obj)
}
interface SearchType {
    [key: string]: string | {}
}
// 获取轮播图
export const BannerGet = (page: number = 1, limit: number = 5, search = {} as SearchType) => {
    for (let i in search) {
        if (search[i] == '') {
            delete search[i];
        }
    }
    if (search.name) {
        search.name = { "$regex": `${search.name}`, "$options": "i" }
    }
    let skip = (page - 1) * limit
    return request.get('classes/banner', {
        params: {
            limit,
            count: 1,
            skip,
            where: search
        }
    })
}

// 更新轮播数据
export const BannerUpdate = (id: string, obj: BannerType) => {
    return request.put('classes/banner/' + id, obj)
}
// 删除轮播数据
export const BannerDel = (id: string) => {
    return request.delete('classes/banner/' + id)
}

// 获取电脑端轮播图
export const BannerPc = () => {
    return request.get('classes/banner', {
        params: {
            where: {
                type: '电脑端'
            }
        }
    })
}


// 获取学员信息

export const StuInfoGet = (page: number = 1, limit: number = 5, search = {} as SearchType) => {
    for (let i in search) {
        if (search[i] == '') {
            delete search[i];
        }
    }
    if (search.createdAt) {
        if (search.createdAt == '近30天') {
            delete search.createdAt
        } else {
            search.createdAt = { "$gte": { "__type": "Date", "iso": "2023-08-17T00:00:00.000Z" }, "$lt": { "__type": "Date", "iso": "2023-08-19T00:00:00.000Z" } }
        }
    }
    // createdAt:{"$gte":{"__type":"Date","iso":"2023-08-14T16:00:00.000Z"},"$lt":{"__type":"Date","iso":"2023-08-14T16:00:00.000Z"}}}
    let skip = (page - 1) * limit
    return request.get('classes/student', {
        params: {
            limit,
            count: 1,
            skip,
            where: search
        }
    })
}